package util

func GetCommand(payload []byte) (s string)  {

	if len(payload) < 5{
		s = "ERROR"
		return
	}
	length := int(uint32(payload[0]) | uint32(payload[1])<<8 | uint32(payload[2])<<16)
	var commandType byte = payload[4]
	if length > len(payload)-4 {
		return "NEEDMORE"
	}
	switch commandType {
	case 3:
		s= String(payload[5:])
		break
	case 1:
		s = "CLOSE"
		break
	default:
		if length > 32 {
			for i := 13 ; i<36;i++{
				if payload[i] != 0{
					s = "ERROR"
					return
				}
			}
		}
		s = "LOGIN"
	}

	return
}
